package org.one.stone.soup.db.processors;

import org.one.stone.soup.core.javascript.JavascriptEngine;

public class DBJavascriptEngine extends JavascriptEngine {
	
	public JSON toJSON(String record) {
		Object js;
		try {
			String name = record.substring(0,record.indexOf(":"));
			
			String script = "obj = {"+record+"}."+name+";\n";
			script += "obj.self = obj;";
			script += "obj.getName = function() { return \""+name+"\"; };\n";
			script += "obj.getDouble = function(path) { return this.self[path]; };\n";
			script += "obj.getLong = function(path) { return this.self[path]; };\n";
			script += "new org.one.stone.soup.db.processors.JSON(obj);";
			js = runScript( script );
			
			return (JSON)js;
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}

}
